﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RayTracing
{
    public class DirectionalLight : Light
    {
        public P3 direction;                                            // Direction the light is heading/coming from? -- ask jp            
        public Color lightColor;                                        // Color of the Light.

        public DirectionalLight(P3 position, Color lightColor)          // Basic constructor for a Directional Light.
        {
            this.direction = P3.normalize(position);                    // Normalizes the position to get a direction.
            this.lightColor = lightColor;
        }

        #region Light Members

        public Color illumination(P3 p, SceneObject sceneObj)           // illmination method returns the color at a point on
        {                                                               // the surface p.
            P3 surfaceNorm = sceneObj.geometry.normal(p);               // Finds the srufaceNormal of the SceneObject at point p.
            float shade = P3.dot(surfaceNorm, this.direction);          // calculates the (percent??) of shade at the point p.
            

            if (shade < 0 || Main.occluded(new Ray(p,this.direction),sceneObj,Main.infinity))  // checks to see if the object is occluded(shadowed) or not.
            {                                                                                  // and how shaded it is. 
                return Color.BLACK;                                     // if occluded or is not hit by this light return Black.
            }
            else
            {
                return Color.scale(this.lightColor, shade);             // if not in shadow and is hit by this light scale the color
            }                                                           // of the light to the shade of the color.
        }

        #endregion
    }
}
